package oop.ex1.actions;

import java.io.File;
import java.util.Date;

/**
 * a class used to print the data of the files
 * @author danalmog
 * @author danielshalev
 */
public class PrintData extends Actions {
	private static final int SIZE_CONVERTER = 128;
	char hidden;
	char writable;
	char exexutable;
	double fileSize;
	Date modDate;
	String filePath;
	
	/**
	 * construct a new object and saves the file relevant properties in fields
	 * @param file the file that is data is being printed
	 */
	public PrintData(File file){
		super(file);
		//check the hidden state of the file
		this.hidden=file.isHidden()? 'h' : '-';
		//check the writable state of the file
		this.writable=file.canWrite() ? 'w' : '-';
		//check the Executable state of the file
		this.exexutable=file.canExecute()? 'x' : '-';
		//calculates the size of the file
		this.fileSize=(double)file.length()/SIZE_CONVERTER;
		this.modDate= new Date(file.lastModified());
		this.filePath= new String(file.getAbsolutePath());
	}
	
	/**
	 * a method that prints the file data 
	 */
	public void doAction(){
		System.out.print(hidden);
		System.out.print(writable);
		System.out.println(exexutable + " " + fileSize + " " + modDate.toString() + " " + filePath);
	}
}